<?php
namespace Home\Controller;
use Think\Controller;
class OrderController extends Controller{
	public function _initialize(){
		if($_COOKIE["manager_id"] == null){
			$index = new IndexController();
			$index->login();exit;
		}
	}
	
	public function index(){
		
	}
	public function showOrder(){
		$sql="select sum(j_price) from task where status ='finish' and pay_status = 'pay'";
		$allmoney = M("Task")->query($sql);
		$this->assign("allmoney",$allmoney[0]["sum(j_price)"]);
		$this->display();
	}
	public function getOrder(){
		$o=M("Order");
		$sql = "select t.*,u.username,u.mobile as usermobile from task as t left join user as u on t.user_id = u.id where status ='finish' and pay_status = 'pay'";
		$orders = $o->query($sql);
		for($i=0;$i<count($orders);$i++){
			$e_id=$orders[$i]["erector_id"];
			$sql = "select e.realname as erectorname,u.mobile as erectormobile from erector as e left join user as u on e.user_id = u.id where e.user_id = $e_id";
			$e =$o->query($sql);
			$orders[$i]["erectorname"]=$e[0]["erectorname"];
			$orders[$i]["erectormobile"]=$e[0]["erectormobile"];
		}
		echo json_encode($orders);
	}
}